import React from "react";
import {
    renderItems,
    VJsonComponent,
    VJsonComponentBase,
} from "../../factory";
import _ from 'lodash'
export interface FieldsetVJsonProp {
    title?: string
}

export interface PageState extends FieldsetVJsonProp {

}

@VJsonComponent({
    view: 'fieldset'
})
export default class Fieldset extends VJsonComponentBase<FieldsetVJsonProp, PageState> {
    static defaultProps = {
        items: [],
    }
    constructor(props: any) {
        super(props);
        _.defaults(
            props.vjson
        )
    }

    render() {
        const {items} = this.props.vjson
        return (
            // @ts-ignore
            <fieldset className="fieldset-wrap">
                <legend className="fieldset-title">
                    {this.props.vjson.title}
                </legend>
                <div className="fieldset-body">
                    {
                        ...renderItems(this, items)
                    }
                </div>
            </fieldset>
        )
    }
}